package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.entity.RolesModulesEntity;
import com.example.service.RolesModulesService;

@RequestMapping("/rolesModules")
@Controller
public class RolesModulesController {
	
	@Autowired
	private RolesModulesService rmService;
	 
	@RequestMapping("/addRM")
	@ResponseBody
	@Transactional
	public boolean addRM(String parentIds,RolesModulesEntity rme) {
		int flag = 0;
		//根据rId删除权限
		rmService.delRM(rme.getRoleid());
		if (parentIds != null && !"".equals(parentIds) && parentIds != "") {//parentIds为空则视为取消全部权限
			String[] m = parentIds.split(",");
			for (int i = 0; i < m.length; i++) {
				int moduleid=Integer.parseInt(m[i]);
				rme.setModuleid(moduleid);
				flag = rmService.addRM(rme);
				if (flag<=0) {
					return false;
				}
			}
		}
		return flag>0? true:false;
	}
}
